#include <iostream>

#include <cstdlib>

#include <unistd.h>
#include <signal.h>

void work()
{
    std::cout << "print log" << std::endl;
}

void Headler(int signum)
{
    work();
    std::cout << "get a sign number: " << signum << std::endl;
    //exit(1);
    int n = alarm(5);
    std::cout << "剩余时间: " << n << std::endl;
}

int main()
{
    signal(SIGALRM, Headler);
    int n = alarm(10);
    while (1)
    {
        std::cout << "proc is running, pid: " << getpid() << std::endl;
        sleep(1);
    }

    return 0;
}
